package com.vogue.supplymall.order.common;

import com.vogue.supplymall.common.domain.dto.EditCartInfo;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * The type Check cart utils.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-15
 */
public final class CheckCartUtils {

    private CheckCartUtils() {
    }

    /**
     * 库存check
     * 库存为0返回false
     *
     * @return the boolean
     */
    public static Boolean checkInventory() {
        return true;
    }

    /**
     * 可见性check
     * 包括：商品是否隐藏、下架，返回false
     *
     * @return the boolean
     */
    public static Boolean checkVisible() {
        return true;
    }

    /**
     * Check invalid boolean.
     *
     * @param pid the pid
     * @param map the map
     * @return the boolean
     */
    public static Boolean checkInvalid(Map<String, String> pid, Map<String, Object> map) {
        if (map.get("s_invalid").toString().equals("true")
                || map.get("p_invalid").toString().equals("true")
                || map.get("invalid").toString().equals("1")) {
            pid.put(map.get("pid").toString(), map.get("pid").toString());
            return true;
        }
        return false;
    }

    /**
     * Check valid boolean.
     *
     * @param pid the pid
     * @param map the map
     * @return the boolean
     */
    public static Boolean checkValid(Map<String, String> pid, Map<String, Object> map) {
        return pid.size() == 0
                || !pid.entrySet()
                .parallelStream()
                .filter((str) -> str.getKey().equals(map.get("pid").toString()))
                .findFirst().isPresent();
    }

    /**
     * Check add cart parameter boolean.
     *
     * @param editCartInfo  the edit cart info
     * @param loginUserType the login user type
     * @return the boolean
     */
    public static Boolean checkAddCartParameter(EditCartInfo editCartInfo, Integer loginUserType) {
        switch (loginUserType) {
            case 0:
                return null == editCartInfo.getProductId()
                        || null == editCartInfo.getAttrplanid()
                        || null == editCartInfo.getItemQuantity();
            case 1:
                return null == editCartInfo.getProductId()
                        || null == editCartInfo.getAttrplanid()
                        || null == editCartInfo.getStorageId()
                        || null == editCartInfo.getStorage()
                        || StringUtils.isEmpty(editCartInfo.getStorage())
                        || null == editCartInfo.getItemQuantity();
            default:
                return true;
        }
    }

    /**
     * Check update cart parameter boolean.
     *
     * @param editCartInfo  the edit cart info
     * @param loginUserType the login user type
     * @return the boolean
     */
    public static Boolean checkUpdateCartParameter(EditCartInfo editCartInfo, Integer loginUserType) {
        switch (loginUserType) {
            case 0:
                return null == editCartInfo.getOrderId()
                        || null == editCartInfo.getOrderItemId()
                        || null == editCartInfo.getOrderItemProductId()
                        || null == editCartInfo.getItemQuantity();
            case 1:
                return null == editCartInfo.getOrderId()
                        || null == editCartInfo.getOrderItemId()
                        || null == editCartInfo.getOrderItemProductId()
                        || null == editCartInfo.getItemQuantity()
                        || null == editCartInfo.getStorageId()
                        || StringUtils.isEmpty(editCartInfo.getStorage())
                        || null == editCartInfo.getStorage();
            default:
                return true;
        }
    }

    /**
     * Check remove cart parameter boolean.
     *
     * @param editCartInfo the edit cart info
     * @return the boolean
     */
    public static Boolean checkRemoveCartParameter(EditCartInfo editCartInfo) {
        return null == editCartInfo.getRemoveId()
                || editCartInfo.getRemoveId().size() <= 0;
    }

}
